package com.sso.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 类 {@code XSSFilter} XSS攻击拦截器 <br> XSS攻击拦截器.
 *
 * <p>详细描述
 * <p>
 *
 * @author <a href="mailto:lz2392504@gmail.com">CN華少</a>
 * @see ServletException
 * @since v1.0.0
 */
public class XSSFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    /**
     * 拦截器实现
     * @param servletRequest
     * @param servletResponse
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("-------------- 开始拦截器 -------------");
        XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper(
                (HttpServletRequest) servletRequest);
        filterChain.doFilter(xssRequest, servletResponse);
        System.out.println("-------------- 结束拦截器 -------------");
        System.out.println("-------------------------------------");
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
